#!/data/data/com.termux/files/usr/bin/bash
DIR=$(
	cd $(dirname $0)
	pwd
)
FONTS_DIR=$DIR/fonts
count=0

echo -e "The default font is Iosevka.\nYou can choose another one from list below."
echo '您可以在此列表中选择终端字体。'
for font in $FONTS_DIR/*/{*.ttf,*.otf}; do
	font_file[count]=$font
	echo "[$count] $(echo ${font_file[count]} | awk -F'/' '{print $NF}')"
	count=$(($count + 1))
done
count=$(($count - 1))

while true; do
	read -p '请输入选项数字,并按回车键,留空不更改。Please type the option number and press Enter:' number

	if [[ -z "$number" ]]; then
		break
	elif ! [[ $number =~ ^[0-9]+$ ]]; then
		echo "Please enter the right number."
	elif (($number >= 0 && $number <= $count)); then
		cp -fr "${font_file[number]}" "$DIR/font.ttf"
		break
	else
		echo "Please enter the right number."
	fi
done

termux-reload-settings
